/**
 * @param {number[]} nums
 * @return {number}
 */
var maxSubarraySumCircular = function(nums) {
    const dp = [nums[0]];
    const leftMax = [nums[0]];
    let res = nums[0], leftSum = nums[0];
    for(let i = 1; i<nums.length; i++) {
        dp[i] = Math.max(nums[i], dp[i-1]+nums[i]);
        res = Math.max(dp[i], res);
        leftSum += nums[i];
        leftMax[i] = Math.max(leftSum, leftMax[i-1]);
    }
    // 反方向计算环形
    let rightSum = 0
    for(let i = nums.length-1; i>=1; i--) {
        rightSum += nums[i];
        res = Math.max(res, leftMax[i-1] + rightSum);
    }
    return res;
};
let res = maxSubarraySumCircular([5, -3, 5]);
console.log(res);